package com.class04.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/13 14:32
 */
public class MyInterceptor1 implements HandlerInterceptor {
    /**
     * 执行handler之前！调用的拦截方法！
     * 编码格式设置，登录保护。权限处理（springSecurity/shiro）！！！
     * filter - doFilter
     * @param request 请求对象
     * @param response 响应对象
     * @param handler  handler就是我们要调用的方法对象
     * @return   ture 放行   false拦截
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("MyInterceptor1.preHandle 4444");
        return true;
    }


    /**
     * 当handler执行完毕后。出发的方法！没有拦截机制了！
     * @param request 请求
     * @param response 响应
     * @param handler handler方法
     * @param modelAndView 返回的视图和共享域数据对象
     * (can also be {@code null})
     * @throws Exception
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("MyInterceptor1.postHandle 5555");
    }

    /**
     *
     * @param request 请求
     * @param response 响应
     * @param handler handler方法
     * @param ex handler报错了  异常对象
     * @throws Exception
     */

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("MyInterceptor1.afterCompletion 6666");
    }
}
